package controler;

import job.Controler;
import java.awt.event.*;

/** Récupere les inputs clavier */
public class KeyboardListener implements KeyListener, Controler {
	private boolean downIsPressed;
	private boolean leftIsPressed;
	private boolean rightIsPressed;
	private boolean upIsPressed;
	public KeyboardListener() {
		downIsPressed = false;
		leftIsPressed = false;
		rightIsPressed = false;
	}
	public void keyPressed(KeyEvent evt) {
		switch(evt.getKeyCode()) {
			case KeyEvent.VK_DOWN:
				downIsPressed = true;
				break;
			case KeyEvent.VK_RIGHT:
				rightIsPressed = true;
				break;
			case KeyEvent.VK_LEFT:
				leftIsPressed = true;
				break;
			case KeyEvent.VK_UP:
				upIsPressed = true;
				break;
		}
	}
	public void keyReleased(KeyEvent evt) {
	}
	public void keyTyped(KeyEvent arg0) {
	}
	public boolean downMoveIsRequest() {
		if(downIsPressed) {
			downIsPressed = false;
			return true;
		}
		else
			return false;
	}
	public boolean leftMoveIsRequest() {
		if(leftIsPressed) {
			leftIsPressed = false;
			return true;
		}
		else
			return false;
	}
	public boolean rightMoveIsRequest() {
		if(rightIsPressed) {
			rightIsPressed = false;
			return true;
		}
		else
			return false;
	}
	public boolean turnMoveIsRequest() {
		if(upIsPressed) {
			upIsPressed = false;
			return true;
		}
		else
			return false;
	}
}
